/**
 * The ButtonItem user-interface component and tag conversor class
 * @class syslib.ui.ButtonItem
 * @author Gabriel Ricci
 */
syslib.ui.ButtonItem = __class();
syslib.ui.ButtonItem.extend(syslib.ui.VisualTag);
syslib.ui.ButtonItem.extend(
/**
 * @lends syslib.ui.ButtonItem
 */
{
	// some class attributes
	id : "",
	title : "", 
	index : 0,
	parent : null, 
	
	// set the parent tag
	__parentTagName : "buttonmenu",

	prepare : function(){
		// set some important stuff
		this.id = "";
		this.title = "";
		this.index = 0;
		this.parent = this.__parent;

		// set the id
		this.id = (__valid(this.__attributes.id)) ? this.__attributes.id : this.parent.id + "_buttonitem_" + Math.floor(Math.random() * 101);
		this.title = (__valid(this.__attributes.title)) ? this.__attributes.title : "";
		
		// return
		return true;
	},

	execute : function(element){
		// set the attributes of the element
		var attributes	= syslib.object.extend(this.__attributes, {
			"class" : "buttonitem-container-normal"
		});
		
		// create the json structure
		elemtJSON = ["div", attributes,
						this.__innerHTML
					];

		// create the element
		var buttonItem = this.createDOM(elemtJSON);
		
		// set some important stuff
		buttonItem._selected = false;

		// return
		return buttonItem;
	},

	finalize : function(){
		// add the item into the father
		this.index = this.parent.addChild(this);

		// check if this item must be selected
		if(this.__attributes.selected === "true"){
 			this.parent.selectChild(this.index);
		}
		
		// create the events
		syslib.event.listen("click", this.__element, function(){
			this.parent.selectChild(this.index);
		}.applyTo(this));
		
		syslib.event.listen("mouseover", this.__element, function(){
			this.__over();
		}.applyTo(this));

		syslib.event.listen("mouseout", this.__element, function(){
			this.__unselect();
		}.applyTo(this));
	},

	__select : function(){
		this.__element._selected = true;
	},

	__over : function(){
		this.__element.className = "buttonitem-container-over";
	},

	__unselect : function(){
		this.__element.className = "buttonitem-container-normal";
		this.__element._selected = false;
	}
});